#property copyright "Babs & Chris Corp."
#property link      "http://www.google.fr"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Gold

double buy_buffer[];
double sell_buffer[];
extern int FasterEMA = 8;
extern int SlowerEMA = 13;
double last_time;

int init() {
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, buy_buffer);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, sell_buffer);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int min_shift;
   double faster_iMA_2;
   double slower_iMA_2;
   double faster_iMA_3;
   double slower_iMA_3;
   double faster_iMA_1;
   double slower_iMA_1;
   double div_totalSize;
   double totalSize;
   int barsCalculated = IndicatorCounted();
   if (barsCalculated < 0) return (-1);
   if (barsCalculated > 0) barsCalculated-- ;
   int li_0 = Bars-barsCalculated;
   for (int shift = 0; shift <= li_0; shift++) {
      min_shift = shift;
      div_totalSize = 0;
      totalSize = 0;
      for (min_shift = shift; min_shift <= shift + 9; min_shift++) totalSize += MathAbs(High[min_shift] - Low[min_shift]);
      div_totalSize = totalSize / 10.0;
      faster_iMA_2 = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, shift);
      faster_iMA_3 = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      faster_iMA_1 = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, shift - 1);
      slower_iMA_2 = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, shift);
      slower_iMA_3 = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      slower_iMA_1 = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, shift - 1);
      
      if (faster_iMA_2 > slower_iMA_2 && faster_iMA_3 < slower_iMA_3 && faster_iMA_1 > slower_iMA_1) buy_buffer[shift] = Low[shift] - div_totalSize / 2.0;
      else
         if (faster_iMA_2 < slower_iMA_2 && faster_iMA_3 > slower_iMA_3 && faster_iMA_1 < slower_iMA_1) sell_buffer[shift] = High[shift] + div_totalSize / 2.0;
      if (faster_iMA_2 > slower_iMA_2 && faster_iMA_3 < slower_iMA_3 && faster_iMA_1 > slower_iMA_1) {
         buy_buffer[shift] = Low[shift] - div_totalSize / 2.0;
         if (last_time != Time[0]) {
            last_time = Time[0];
         }
      } else {
         if (faster_iMA_2 < slower_iMA_2 && faster_iMA_3 > slower_iMA_3 && faster_iMA_1 < slower_iMA_1) {
            sell_buffer[shift] = High[shift] + div_totalSize / 2.0;
            if (last_time != Time[0]) {
               last_time = Time[0];
            }
         }
      }
   }/*
   if(buy_buffer[0] != 2147483647.00000000)
      Print("buy_buffer BUY 0: "+sell_buffer[0]);
   if(sell_buffer[0] != 2147483647.00000000)   
      Print("sell_buffer SELL 1: "+sell_buffer[0]);
      iCustom(NULL,StealthTF,"Stealth Earlybird V1",8,9,0,0);
*/
   return (0);
}